var orderFood = {
	show : function(transtion) {
		var db = app.getDB();
		db.transaction(function(tx) {
			tx.executeSql('select * from category order by sort', [], function(tx, results) {
				var len = results.rows.length;
				if (len == 0) {
					app.msg.comfirm("提示", "您还没有配置菜系,现在是否进行配置?", function() {
						category.show(null,'pages/home.html');
						jsTouch.overlayClose();
					}, function() {
						jsTouch.overlayClose();
						orderFood.showHtml([], transtion);
					})

				} else {
					var data = [];
					for (var i = 0; i < len; i++) {
						data.push(results.rows.item(i));
					}
					orderFood.showHtml(data, transtion);
				}

			}, errorCB);
		}, errorCB);
		orderFood.loadAllFood();
	},
	showHtml : function(data, transtion) {

		var template = $.createTemplateURL('templates/order_food.html');
		var html = template.get(data);
		app.loadHTML(html, {
			transition : transtion
		});
		if (data.length > 0) {
			$(".category  a").first().click();
		}

	},
	loadAllFood : function() {
		var db = app.getDB();
		db.transaction(function(tx) {
			tx.executeSql('SELECT * FROM MENU', [], function(tx, results) {
				var len = results.rows.length;
				var foodList = [];
				for (var i = 0; i < len; i++) {
					var foodItem = results.rows.item(i);
					foodList.push(foodItem);
				}
				allMenu = foodList;
			}, errorCB);

		}, errorCB);
	},
	loadFoodList : function(categoryId) {
		var db = app.getDB();
		db.transaction(function(tx) {
			tx.executeSql('SELECT * FROM MENU WHERE CATEGORY_ID =? ORDER BY NAME ', [categoryId], function(tx, results) {
				var len = results.rows.length;
				var template;
				if (len > 0) {
					template = $.createTemplateURL('templates/order_food_foodlist.html');
				} else {
					template = $.createTemplateURL('templates/order_food_foodlist_empty.html');
				}
				var foodList = [];
				for (var i = 0; i < len; i++) {
					var foodItem = results.rows.item(i);
					var count = bill.getMenuCount(foodItem.id);
					foodItem.count = count;
					foodList.push(foodItem);
				}
				var html = template.get(foodList);
				app.loadHtmlById('foodListId', html);
			}, errorCB);

		}, errorCB);
	},
	showOrderList : function() {

	}
};